function [gaps,int_macrov]=macrogapsnew(macrov,parms,int_macrov,critl,maxit);


% recover macro variables,parms
recvpnew



%% The Macro Gaps

%%%%%%%%%%%%%%%%%%%%%%
%        GAPS        %
%%%%%%%%%%%%%%%%%%%%%%


nmac=length(macrov);
gaps=zeros(nmac,1);
place = 0;

% equation (22)
place = place+1;
[gi,dgi] = gcost(macrov,parms);
gaps(place) = gi*Q - in - xistar;

% equation (23) [in Miao & Wang]
place = place+1;
gaps(place) = 1 - Q*dgi; 

% equation (24)
place = place+1;
gaps(place) = log(in) + log(K) + Ftilde - log(bigI);

% equation (25)
place = place+1;
gaps(place) = K - (1-delta)*K - gi*exp(Ftilde)*K;

% equation (26a)
place = place+1;
[F,junk1,junk2] = prodf(macrov,parms);
gaps(place) = Y - F;

% equation (26b)
place = place+1;
gaps(place) = bigI + C + K*bigxi - Y;

% equation (27)
place = place+1;
d1U = C^-sig;
d2U = -chi*(N^eta);
[F,F1,F2] = prodf(macrov,parms);
gaps(place) = Abar*F2 + d2U/d1U;

% equation (28)
place = place+1;
biglam_ss = xistar*phi0 - bigxi;
gaps(place) = F1 + (1-delta)*Q + biglam_ss - (1/b)*Q;

% % new equation
% place = place+1;
% gaps(place) = xistar*phi0 - bigxi - biglam_ss;















